<?php
 header("Content-type: application/vnd.ms-excel");
 header("Content-Disposition:  filename=\"Usuarios_Cladea2012.XLS\";");
?>

<?php
include_once '../../Config/config.php';
include_once '../../Config/conexion.php';
include_once '../../Model/Paper.php';

include_once '../../Model/Track.php';
include_once '../../Model/Idioma.php';
include_once '../../Model/Rol.php';
include_once '../../Model/Revisor.php';

$usuario = Util::ObtenerSession();
$track_id = "";					
if($usuario->Roles[0]->Id == 6){
	$track_id = $usuario->Track->Id;
}

$idrol = isset($_REQUEST["idrol"])?$_REQUEST["idrol"]:"";
$idpais = isset($_REQUEST["idpais"])?$_REQUEST["idpais"]:"";
?>
	<script>
		$(document).ready(function(){
			$(".ficha").click(function(){
				//alert(123);
				
				var obj = $(this);				
				$.ajax({
					url:URL_PAGE+"Modulos/Usuarios/Ficha.php",
					data : {idusuario : obj.attr("data-id")},
					type:"post",
					success:function(data){
						$("#window-modal").html(data);
						$("#window-modal").dialog(
							{
								autoOpen: true,
								width: 820,
								maxheight: 600,
								resizable: false,
								modal: true,
								show: 'slide',
								hide: 'slide',
								position: ["center",100],
								title: "Agregar Usuario",
								open: function (event, ui) {
									var parent = $(this);
									$('.ui-widget-overlay').click(function () {
										parent.dialog("close");
									})                        
								},
								close: function (event, ui) {                        
								}
							}
						)
					}
				});
			
			})
		});
	</script>

	
	<table class="tabla-basica">	
	<thead>
		<tr>
			<th>#</th>
			<th>
				Nombre completo
			</th>
            	<th>
				Email
			</th>
			<th>
				Instituci&oacute;n
			</th>			
			<th>
				Pa&iacute;s
			</th>
			
			<?php
			if($idrol != "1"){
			?>			
			<?php
			}
			?>			
			<th>
				Rol
			</th>	
        </tr>
	</thead>
	<tbody>	
		<?php
								
				$lista = Usuario::ListarPorRol($idrol,0,$idpais);	

				$fila = 0;
				foreach($lista as $row){
					
					if($idrol == 2){
						$revisor = Revisor::Obtener($row->IdUsuario);
						$tracks = explode("," ,$revisor->Tracks);
						if($track_id != ""){
							if(!in_array($track_id, $tracks)){
								continue;
							}
						}
					}
					$fila++;
		?>
				<tr>
					<td><?php echo $fila;?></td>
					<td>
						<?php echo htmlentities($row->Nombres)?> <?php echo htmlentities($row->Paterno)?> <?php echo htmlentities($row->Materno)?>
						<br>
						
					</td>
                    <td>
						<?php echo $row->Email?>
					</td>
					<td>
						<?php
							if($row->Institucion != null)
							{
						?>
						<?php echo htmlentities($row->Institucion->Nombre)?>
						<?php
							}
						?>
					</td>					
					<td>
						<?php echo htmlentities($row->Pais->Nombre)?>
					</td>
					
						<?php
							if($idrol != "1"){
						?>
						<?php
							}
						?>
										
					<td>
						<?php echo $row->Rol->Nombre?>
					</td>
                </tr>
		<?php
				}
		?>
		
	</tbody>
	</table>
	